package com.patternsbox.structural.composite;

import java.util.ArrayList;
import java.util.List;

class Composite extends Component {

	private List<Component> children = new ArrayList<Component>();

	public Composite(String name) {
		super(name);
	}

	public void add(Component leaf) {
		children.add(leaf);
	}

	public void remove(Component leaf) {
		children.remove(leaf);
	}
	
	@Override
	public void display(int depth) {
		super.display(depth);
		// Recursively display child nodes
		for (Component component : children) {
			component.display(depth + 2);
		}		
	}

	@Override
	public boolean isComposite() {
		return true;
	}
}
